<?
/*

phyoCalendar.class.php v1.0 example

Just copy and paste all this code into your existing code.
Modify the style a bit and make sure the phyoCalendar.class.php
is in the same directory as this page.

pazu@phyo.net

*/

include("phyoCalendar.class.php");
function showCalendar($staffid="",$calurl="")
{
	if($calurl=="") 
	$calurl = $_SERVER['PHP_SELF'];

	$tstamp = $_GET['stamp'];
	if($tstamp=="") 
		$tstamp=mktime();
	$thisMonth = (!empty($tstamp)) ? date('m', $tstamp) : date("m");
	$thisYear = (!empty($tstamp)) ? date('Y', $tstamp) : date("Y");

	$cal = new Calendar($thisMonth, $thisYear);

	$wday_index = array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');
	?>

	<style>
		.calTable {background:#CCCCCC;}
		.calTitle { font-weight:bold; text-align:center;}
		.calDayname {text-align:center;width:22px;height:15px;background-color:#f4f4f4;}
		.calToday {background-color:#FFFF00; color:#FF0000; text-align:center; vertical-align:top;}		
		.calDay { text-align:center;width:22px;height:15px; vertical-align:top;}
		.calDayReserved { text-align:center;width:22px;height:15px; vertical-align:top; background-color:#6F6F6F;}
		a.calDay:link, a.calDay:visited {text-decoration:none; display:block; color: #000000 }
		a.calDay:hover {text-decoration:none; display:block;background-color:#CCCCCC;}
		a.calNav { text-decoration:none;}
		a.calNav:hover {text-decoration:underline;}
	</style>
	<table class="calTable" cellspacing="1">
	<tr bgcolor="#f4f4f4"><td colspan="8">
		<table width="100%" border="0">
		<tr>
			<td align="left"><a class="calNav" href="<?= $calurl.'?stamp='.$cal->getLastMonth().'&staff_id='.$staffid ?>">&laquo; Prev</a></td>
			<td class="calTitle"><?= date("M Y", mktime(0,0,0,$cal->month, 1, $cal->year)) ?></td>
			<td align="right"><a class="calNav" href="<?= $calurl.'?stamp='.$cal->getNextMonth().'&staff_id='.$staffid ?>">Next &raquo;</a></td>
		</tr>
		</table>
	</td></tr>
	<tr bgcolor="#FFFFFF"><td class="calDayname">
		<? echo implode("</b></td><td class=\"calDayname\">", $wday_index) ?>
	</td></tr>

	<? 
		$fromdate = date("Y",$tstamp)."-".date("m",$tstamp)."-01";
		$todate = date("Y",$tstamp)."-".date("m",$tstamp)."-".date("t",$tstamp);
		$companyOff = getPureDaysoff($fromdate, $todate, "company");
		
		if(is_numeric($staffid) and $staffid > 0) {
			$staffOff = getPureDaysoff($fromdate, $todate, "staff",$staffid);
			$companyOff = array_merge($companyOff, $staffOff);
			$companyOff = array_unique($companyOff);
		}

		foreach ($cal->getCalendarMonth('d') as $stamp) {
		echo '<tr bgcolor="#FFFFFF">';
		for ($i=0; $i < count($wday_index); $i++) {
			$theDay = $stamp[$wday_index[$i]];
			$theDay_t = $cal->getTimestamp($theDay);
			
			if($theDay_t != "") {
			$db_date = date("Y-m-d", $theDay_t);
			if(in_array($db_date,$companyOff) || in_array(date("w",$theDay_t),$companyOff))
				$notavial = "reserved";
			else 
				$notavial = "";
			}
			echo dateCell($theDay_t,$notavial,$calurl,$tstamp);
		}
		echo "</tr>";
		} 
	?>
		<tr>
			<td class="calDay" colspan="8"><a class="calNav" href="<?= $calurl.'?stamp='.mktime() ?>">&laquo;Today&raquo;</a></td>
		</tr>
	</table>
<?
}
?>